package com.llc.station.kcp.ui.core.component;

import com.llc.station.kcp.ui.core.bean.MacCar;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;


/**
 * 作者 zxj<br>
 * 时间 2017/9/13 10:39
 * 说明 油机的主要内容的pane
 */
public class MacCarMainContentPane extends VBox {

    /**
     * 油品，如98 95
     */
    protected String oilType;
    /**
     * 距离上方的距离
     */
    protected double topMargin;
    protected int topPadding = 10;
    /**
     * 画的那根线与左右两侧的距离
     */
    protected double lineMargin = 10;

    protected CarMainContentInfo carMainContentInfo;


    public MacCarMainContentPane(String oilType, double topMargin) {
        this.oilType = oilType;
        this.topMargin = topMargin;
    }

    public MacCarMainContentPane(double spacing, String oilType, double topMargin) {
        super(spacing);
        this.oilType = oilType;
        this.topMargin = topMargin;
    }

    public MacCarMainContentPane(String oilType, double topMargin, Node... children) {
        super(children);
        this.oilType = oilType;
        this.topMargin = topMargin;
    }

    public MacCarMainContentPane(double spacing, String oilType, double topMargin, Node... children) {
        super(spacing, children);
        this.oilType = oilType;
        this.topMargin = topMargin;
    }

    /**
     * 更新列表中的内容
     * @param carMainContentInfo
     */
    public void updateContent(CarMainContentInfo carMainContentInfo){
        if(carMainContentInfo == null){
            throw new NullPointerException("传入的油机车辆详情不能为空");
        }
        this.getChildren().clear();
        this.carMainContentInfo = carMainContentInfo;

        double width = getPrefWidth();
        double height = getPrefHeight();

        height = height - topMargin;
        AnchorPane anchorPane = new AnchorPane();
        anchorPane.setPrefWidth(width);
        anchorPane.setPrefHeight(height);
        //VBox.setMargin(anchorPane,new Insets(topMargin + topPadding,0,0,0));
        VBox.setMargin(anchorPane,new Insets(topMargin,0,0,0));

        VBox vBox = new VBox();
        anchorPane.getChildren().add(vBox);
        AnchorPane.setTopAnchor(vBox,0.0);
        vBox.setAlignment(Pos.CENTER);
        //vBox.setBackground(new Background(new BackgroundFill(Color.TEAL,new CornerRadii(0),new Insets(0,0,0,0))));//


        Label qtyMoney = new Label("" + carMainContentInfo.getQty() + "L     ¥" + carMainContentInfo.getMoney());
        qtyMoney.getStyleClass().add("mainContent-qtyMoney");
        vBox.getChildren().add(qtyMoney);
        //Line line = new Line(lineMargin,0,width - lineMargin,0);
        Line line = new Line(0,0,width - lineMargin * 2,0);
        VBox.setMargin(line,new Insets(0,0,0,lineMargin));
        line.setStrokeWidth(2);
        vBox.getChildren().add(line);

        HBox hBox = new HBox();
        VBox.setMargin(hBox,new Insets(6,0,0,0));
        hBox.setAlignment(Pos.CENTER);
        Label status = new Label(carMainContentInfo.getStatus());
        status.setBackground(new Background(new BackgroundFill(carMainContentInfo.getStatusColor(),new CornerRadii(0),Insets.EMPTY)));
        status.getStyleClass().add("mainContent-status");
        hBox.getChildren().add(status);

        Label per = new Label(String.valueOf(carMainContentInfo.getPer()) + "%");
        HBox.setMargin(per,new Insets(0,0,0,8));
        per.getStyleClass().add("mainContent-per");
        hBox.getChildren().add(per);
        vBox.getChildren().add(hBox);

        HBox carNumberTag = new HBox();
        carNumberTag.setPrefWidth(width);
        VBox.setMargin(carNumberTag,new Insets(10,0,0,0));
        carNumberTag.setAlignment(Pos.CENTER);
        Label carNumber = new Label(carMainContentInfo.getCarNumber());
        carNumber.getStyleClass().add("mainContent-carNumber");
        carNumberTag.getChildren().add(carNumber);


        Label tag = new Label(carMainContentInfo.getTag());
        tag.getStyleClass().add("mainContent-tag");
        HBox.setMargin(tag,new Insets(0,0,0,5));
        tag.setBackground(new Background(new BackgroundFill(carMainContentInfo.getTagColor(),new CornerRadii(50),Insets.EMPTY )));
        carNumberTag.getChildren().add(tag);

        vBox.getChildren().add(carNumberTag);




        HBox di = new HBox();
        di.getStyleClass().add("mainContent-di");
        di.setPrefWidth(width);
        Label x = new Label("18");
        x.getStyleClass().add("mainContent-di-num");
        di.getChildren().add(x);

        Label text = new Label("未关联车记录 共2笔");
        HBox.setMargin(text,new Insets(0,0,0,5));
        text.getStyleClass().add("mainContent-di-text");
        di.getChildren().add(text);
        di.setAlignment(Pos.CENTER);


        anchorPane.getChildren().add(di);
        AnchorPane.setBottomAnchor(di,0.0);

        this.getChildren().add(anchorPane);


    }




    public static class CarMainContentInfo{
        public static final String STATUS_OILING = "加油中";
        public static final String STATUS_WAITPAY = "待付款";
        public static final String STATUS_WRITEOFFED = "已核销";
        /**
         * 车牌号
         */
        private String carNumber;
        /**
         * 加油状态
         */
        private String status;
        /**
         * 会员标签
         */
        private String tag;
        /**
         * 升数
         */
        private double qty;
        /**
         * 金额
         */
        private double money;
        /**
         * 当前加油百分比
         */
        private double per;

        public CarMainContentInfo(String carNumber, String status, String tag, double qty, double money, double per) {
            this.carNumber = carNumber;
            this.status = status;
            this.tag = tag;
            this.qty = qty;
            this.money = money;
            this.per = per;
        }

        public CarMainContentInfo() {
        }

        public Color getStatusColor(){
            if(STATUS_OILING.equals(status)){
                return Color.rgb(6,6,6);
            }else if(STATUS_WAITPAY.equals(status)){
                return Color.rgb(234,140,42);
            }else if(STATUS_WRITEOFFED.equals(status)){
                return Color.rgb(33, 38, 234);
            }else{
                return Color.rgb(221, 223, 234, 0.2588);
            }
        }

        public Color getTagColor(){
            if("免".equals(tag)){
                return Color.rgb(48, 234, 27);
            }else if("专".equals(tag)){
                return Color.rgb(234, 44, 34);
            }else if("会".equals(tag)){
                return Color.rgb(234, 136, 33);
            }else{
                return Color.rgb(234, 217, 225, 0.3686);
            }
        }

        public String getCarNumber() {
            return carNumber;
        }

        public void setCarNumber(String carNumber) {
            this.carNumber = carNumber;
        }

        public String getStatus() {
            return status;
        }

        public void setStatus(String status) {
            this.status = status;
        }

        public String getTag() {
            return tag;
        }

        public void setTag(String tag) {
            this.tag = tag;
        }

        public double getQty() {
            return qty;
        }

        public void setQty(double qty) {
            this.qty = qty;
        }

        public double getMoney() {
            return money;
        }

        public void setMoney(double money) {
            this.money = money;
        }

        public double getPer() {
            return per;
        }

        public void setPer(double per) {
            this.per = per;
        }

        @Override
        public String toString() {
            return "CarMainContentInfo{" +
                    "carNumber='" + carNumber + '\'' +
                    ", status='" + status + '\'' +
                    ", tag='" + tag + '\'' +
                    ", qty=" + qty +
                    ", money=" + money +
                    ", per=" + per +
                    '}';
        }
    }
}
